package org.aeon.client.view.components.sessionPanel;

import lombok.Getter;
import org.aeon.entity.dto.UserInfoDto;

import javax.swing.*;
import java.awt.*;

/**
 * @author: MissingAeon
 * @date: 2024/2/20 14:04
 * @description:
 */
@Getter
public class UserChatPanel extends JPanel {
    private final ChatTopPanel topPanel;
    private final ChatEditorPanel editorPanel;
    private final ChatRecordPanel recordPanel;

    public UserChatPanel() {
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        topPanel = new ChatTopPanel();
        this.add(topPanel);

        // 添加分隔线
        this.addSeparator();

        recordPanel = new ChatRecordPanel(new Dimension(700, 400));
        this.add(recordPanel);

        // 添加分隔线
        this.addSeparator();

        editorPanel = new ChatEditorPanel(new Dimension(700, 240));
        this.add(editorPanel);

        // 相互绑定
        recordPanel.setEditorPanel(editorPanel);
        editorPanel.setRecordPanel(recordPanel);
    }

    public void setTitle(String title) {
        topPanel.setText(title);
    }

    private void addSeparator() {
        // 创建垂直分隔线
        JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
        // 设置分隔线的最大尺寸
        separator.setMaximumSize(new Dimension(700, 5));
        this.add(separator);
    }

    public void fillInData(UserInfoDto user) {
        this.setTitle(user.getNickname());

        topPanel.load(user);
        recordPanel.load(user);
        editorPanel.load(user);

        recordPanel.setScrollBar(-1);
    }
}
